package com.brillilab.service.core.kit.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.brillilab.dao.mapper.kit.KitRegularUsageGroupMapper;
import com.brillilab.domain.po.kit.KitRegularUsageGroup;
import com.brillilab.service.core.kit.IkitRegularUsageGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 常用清单组
 *
 * @author wmh
 */
@Service
@Transactional
public class KitRegularUsageGroupServiceImpl implements IkitRegularUsageGroupService {

    @Autowired
    private KitRegularUsageGroupMapper kitRegularUsageGroupMapper;

    @Override
    public KitRegularUsageGroup selectById(Long regularUsageGroupId) {
        return kitRegularUsageGroupMapper.selectById(regularUsageGroupId);
    }

    @Override
    public boolean insert(KitRegularUsageGroup group) {
        return kitRegularUsageGroupMapper.insert(group) == 1;
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<KitRegularUsageGroup> selectList(Long labId,Long labMemberId) {
        return kitRegularUsageGroupMapper.selectList(
                new LambdaQueryWrapper<KitRegularUsageGroup>()
                        .eq(KitRegularUsageGroup::getLabId,labId)
                        .eq(KitRegularUsageGroup::getLabMemberId,labMemberId)
                        .orderByDesc(KitRegularUsageGroup::getUpdateTime)
        );
    }

    @Override
    public boolean deleteById(Long groupId) {
        return kitRegularUsageGroupMapper.deleteById(groupId) == 1;
    }

    @Override
    public boolean updateById(KitRegularUsageGroup group) {
        return kitRegularUsageGroupMapper.updateById(group) == 1;
    }

    @Override
    public KitRegularUsageGroup selectOne(Long groupId,Long labId,Long labMemberId) {
        return kitRegularUsageGroupMapper.selectOne(
                new LambdaQueryWrapper<KitRegularUsageGroup>()
                        .eq(KitRegularUsageGroup::getLabId,labId)
                        .eq(KitRegularUsageGroup::getLabMemberId,labMemberId)
                        .eq(KitRegularUsageGroup::getId,groupId));
    }
}
